import type { Dayjs } from 'dayjs';

import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace EdubaseSemesterApi {
  /** 学期参数信息 */
  export interface Semester {
    id: number; // 学期主键
    academicYearId?: number; // 学年id
    academicYear: string; // 学年
    period?: number; // 学段
    type?: number; // 学期类型
    semesterCode?: string; // 学期编码
    name: string; // 学期名称
    startDate?: Dayjs | string; // 开始日期
    endDate?: Dayjs | string; // 结束日期
    weekCount: number; // 总周数
    courseStartWeek: number; // 教学课程周开始
    courseEndWeek: number; // 教学课程周结束
    teachingWeeks: number; // 教学周
    examWeeks: number; // 考试周
    holidayWeeks: number; // 假期周
    status: number; // 状态
    isCurrent: number; // 是否当前学期
    metadata?: string; // 学期参数
    remark?: string; // 备注
  }
}

/** 查询学期参数分页 */
export function getSemesterPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<PageResult<EdubaseSemesterApi.Semester>>(
    '/edu/base/semester/page',
    data,
    { desensitize, encrypt },
  );
}

/** 查询学期参数详情 */
export function getSemester(id: number) {
  return requestClient.get<EdubaseSemesterApi.Semester>(
    `/edu/base/semester/get?id=${id}`,
  );
}

/** 新增学期参数 */
export function createSemester(data: EdubaseSemesterApi.Semester) {
  return requestClient.post('/edu/base/semester/create', data);
}

/** 修改学期参数 */
export function updateSemester(data: EdubaseSemesterApi.Semester) {
  return requestClient.put('/edu/base/semester/update', data);
}

/** 删除学期参数 */
export function deleteSemester(id: number) {
  return requestClient.delete(`/edu/base/semester/delete?id=${id}`);
}

/** 批量删除学期参数 */
export function deleteSemesterList(ids: number[]) {
  return requestClient.delete(
    `/edu/base/semester/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出学期参数 */
export function exportSemester(params: any) {
  return requestClient.download('/edu/base/semester/export-excel', { params });
}
